<template>
  <div>
    <!-- 面包屑导航 -->
    <nav-bread name1="数据统计" name2="数据报表"></nav-bread>
    <el-card>
      <!-- 为echarts准备一个具备宽高的DOM -->
      <div id="main" style="height:400px;width:600px"></div>
    </el-card>
  </div>
</template>

<script>
// 导入echarts
import * as echarts from "echarts";
import _ from 'lodash'
export default {
  data() {
    return {
      Options: {
        title: {
          text: "用户来源",
        },
        tooltip: {
          trigger: "axis",
          axisPointer: {
            type: "cross",
            label: {
              backgroundColor: "#E9EEF3",
            },
          },
        },
        grid: {
          left: "3%",
          right: "4%",
          bottom: "3%",
          containLabel: true,
        },
        xAxis: [
          {
            boundaryGap: false,
          },
        ],
        yAxis: [
          {
            type: "value",
          },
        ],
      },
    };
  },
  //    此时页面上的元素已经被渲染完毕了
  async mounted() {
    let myChart = echarts.init(document.querySelector("#main"));
    const { data } = await this.$http.get("reports/type/1");
    if (data.meta.status !== 200) {
      return this.$message.error("获取数据失败");
    }
    const result=_.merge(data.data,this.Options)
    myChart.setOption(result);
  },
};
</script>

<style lang="less" scoped>
</style>>

